<template>
	<view style="" class="flex flex-x-b flex-y-center" :class="scroll?'scroll flex-x-start':''"
		:style="{height,'padding-bottom':paddingB}">

		<template v-if="!scroll">
			<view @tap="channge(key)" style="height: 100%;" class="flex flex-y-center" v-for="(item,key) in list"
				:key="key">
				<view class="tabs-item" :class="tab_index == key ?'tab-active':''"
					:style="size?'font-size:' + (tab_index == key?sizeActive:size):''">{{item.name}}</view>
			</view>
		</template>
		<template v-else>
			<view @tap="channge(key)" style="height: 100%;display: inline-block;" class="flex flex-y-center"
				v-for="(item,key) in list" :key="key">
				<view class="tabs-item" style="margin-right: 36rpx;" :class="tab_index == key ?'tab-active':''"
					:style="size?'font-size:' + (tab_index == key?sizeActive:size):''">
					{{item.name}}
				</view>
			</view>
		</template>

	</view>
</template>

<script>
	export default {
		name: "tabs",
		props: {
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			height: {
				type: String,
				default: '100rpx'
			},
			index: {
				type: Number,
				default: 0,
			},
			//下边距
			paddingB: {
				type: String,
				default: '0rpx'
			},
			//是否可左右滑动
			scroll: {
				type: Boolean,
				default: false,
			},
			size: {
				type: String,
				default: '28rpx',
			},
			sizeActive: {
				type: String,
				default: '32rpx',
			}


		},
		computed: {

		},
		created() {
			this.tab_index = this.index;
		},
		data() {
			return {
				tab_index: 0,
			};
		},
		methods: {
			channge(index) {
				this.tab_index = index;
				this.$emit('change', index);
			}
		}
	}
</script>

<style lang="scss">
	.tabs-item {

		color: #666666;
		font-weight: 400;
		border-radius: 16rpx 0 16rpx 0;
		// padding-top: 10rpx;
	}

	.tab-active {

		font-weight: 500;
		font-size: 40rpx;
		padding-top: 0rpx;
		position: relative;
		color: #333;
	}

	.tab-active::after {
		content: '';
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		bottom: -12rpx;
		width: 44rpx;
		height: 8rpx;
		background: linear-gradient(270deg, #6294FC 0%, #5577E0 100%);
		border-radius: 4px;

	}

	.scroll {
		white-space: nowrap;
	}
</style>
